<?php
include_once "src/controller/dbmanagement/ReservationDBManagement.php";

/**
 * It includes all the functions for the management of the business logic
 * for Reservation.
 *
 * @author: Ngozi Ihemelandu
 */
class ReservationManagement {
    /**
     *Precondition:  Accepts a reservation object: The following attributes MUST be set:
     *                - Reservation_id
     *Postcondition: Find and return a specific reservation in the tReservation table
     *               otherwise return false
     **/
    public static function getReservationByID($Reservation) {
        try {

            return ReservationDBManagement::findSpecificReservation($Reservation);

        } catch (DBException $e) {
            throw $e;
        } catch (DBConnectionException $e) {
            throw $e;
        }

    }

    /**
     *Precondition:  Accepts a reservation object: The following member attribute MUST be set:
     *                - UserID
     *Postcondition: Find all reservations in the tReservation table by a UserID
     *               An Array of Reservation objects is returned
     **/
    public static function getAllReservation($Reservation) {
        try {

            return ReservationDBManagement::findAllreservationRecord($Reservation);

        } catch (DBException $e) {
            throw $e;
        } catch (DBConnectionException $e) {
            throw $e;
        }

    }


    /**
     *Precondition:  Accepts a reservation object: The following attributes MUST be set:
     *                - ReservationID
     *Postcondition: Removes a record from the tReservation table and returns
     *               true if successful and false otherwise.
     **/
    public static function removeReservation($Reservation) {
        try {

            return ReservationDBManagement::deleteReservationByID($Reservation);

        } catch (DBException $e) {
            throw $e;
        } catch (DBConnectionException $e) {
            throw $e;
        }
    }

    /**
     *Precondition:  Accepts a reservation object: The following attributes MUST be set:
     *               - UserID and
     *               - ResourceID
     *Postcondition: Adds a record into the tReservation table and returns
     *               true if successful and false otherwise.
     **/
    public static function addReservation($Reservation) {
        try {

            return ReservationDBManagement::insertReservation($Reservation);

        } catch (DBException $e) {
            throw $e;
        } catch (DBConnectionException $e) {
            throw $e;
        }
    }

    /**
     *Precondition:  Accepts a reservation object: The following attributes MUST be set:
     *                - Resource_id
     *                - User_id
     *                - Reservation_id
     *Postcondition: updates record in the tReservation table by ReservationID
     *               No Value is returned.
     **/
    public static function updateReservation($Reservation) {
        try {

            ReservationDBManagement::updateReservationRecord($Reservation);

        } catch (DBException $e) {
            throw $e;
        } catch (DBConnectionException $e) {
            throw $e;
        }
    }

    /**
     * Finds all the Reservations associated with the given Resource Id.
     *
     * @param $resourceId   The id from the specific resource record.
     * @return              Reservation[]. Returns an array of all
     *                      the Reservations associated to the given Resource Id.
     */
    public static function findAllReservationsByResourceId($resourceId) {
        try {
            return ReservationDBManagement::findAllReservationsByResourceId($resourceId);
        } catch (DBException $e) {
            throw $e;
        } catch (DBConnectionException $e) {
            throw $e;
        }
    }

}
?>
